package com.edu.nju.nationalflag;


import java.util.ArrayList;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;

public class ImageAdapter extends BaseAdapter{
	SearchActivity activity;
	private Context		mContext;
	ImageView imageView;
	
	private Integer[] colorImageIds = new Integer[]{
			R.drawable.color_black,R.drawable.color_blue,R.drawable.color_brown,R.drawable.color_green,
			R.drawable.color_orange,R.drawable.color_purple,R.drawable.color_red,R.drawable.color_white,
			R.drawable.color_yellow
	};
	
	private Integer[] colorYesImageIds = new Integer[]{
			R.drawable.color_black_yes,R.drawable.color_blue_yes,R.drawable.color_brown_yes,R.drawable.color_green_yes,
			R.drawable.color_orange_yes,R.drawable.color_purple_yes,R.drawable.color_red_yes,R.drawable.color_white_yes,
			R.drawable.color_yellow_yes
	};
	
	private ArrayList<Integer> filter = new ArrayList<Integer>();

	public ImageAdapter(Context c,SearchActivity a ,ArrayList<Integer> selected )
	{
		activity = a;
		mContext = c;
		filter = selected;
	}
	
	@Override
	public int getCount() {
		return 9;
	}

	@Override
	public Object getItem(int position) {
		return position;
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		if (convertView == null)
		{
			imageView = new ImageView(mContext);
			imageView.setLayoutParams(new GridView.LayoutParams(175, 175));
			imageView.setScaleType(ImageView.ScaleType.FIT_CENTER);
		}
		else
		{
			imageView = (ImageView) convertView;
		}
		
		if (filter.get(position) == 0){
			imageView.setBackgroundResource(colorImageIds[position]);
		}
		else if (filter.get(position) != 0){
			imageView.setBackgroundResource(colorYesImageIds[position]);
		}
		
		
		return imageView;
	}

}
